Page({
  data: {
    numbers: [],
    isGenerating: false,
    timer: null,
    buttonTitle: '开始',
  },

  onLoad: function() {
    // 页面加载时初始化生成数字
    this.generateNumbers();
  },

  generateNumbers: function() {
    const that = this;
    if (this.data.isGenerating) {
      // 如果已经在生成数字，停止生成
      clearInterval(this.data.timer);
      this.setData({
        isGenerating: false,
        buttonTitle: '开始',
      });
    } else {
      // 开始生成数字
      this.setData({
        isGenerating: true,
        buttonTitle: '暂停',
      });
      this.data.timer = setInterval(function() {
        that.updateNumbers();
      }, 100); // 每100毫秒更新一次数字
    }
  },

  updateNumbers: function() {
    const numbers = [];
    numbers.push(this.getRandomNumbers(16, 1)[0]); // 先添加1-16的数字
    numbers.push(...this.getRandomNumbers(33, 6)); // 然后添加1-33的数字
    this.setData({
      numbers: numbers,
    });
  },

  getRandomNumbers: function(max, count) {
    const numbers = new Set();
    while (numbers.size < count) {
      const randomNumber = Math.floor(Math.random() * max) + 1;
      numbers.add(randomNumber);
    }
    return Array.from(numbers);
  },
});